<?php
require_once dirname(__FILE__) .'/cse-config.php';

// auto detect file system path
if ( !defined('CSEPATH') ) {
	$csepath = str_replace('\\', '/', dirname(__FILE__));	
	$csepath = preg_replace('!/\.[a-zA-Z]+/!', '/', $csepath);
	define('CSEPATH', $csepath);
	define('CSECORE', CSEPATH .'/core');
	unset($csepath);
}

// auto detect requested file (relative to file system path and url)
$csefile = preg_replace('!/\.[a-zA-Z]+/!', '/', $_SERVER['SCRIPT_FILENAME']);
$csefile = preg_replace('!^'. preg_quote(CSEPATH) .'!', '', $csefile);
define('CSEFILE', $csefile);
unset($csefile);

// auto detect url
if ( !defined('CSEURL') ) {
	$cseurl = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
	$cseurl .= $_SERVER['HTTP_HOST'];
	if ( strcmp($_SERVER['SERVER_PORT'], '80') != 0 ) {
		$cseurl .= ':80';
	}
	$cseurl .= $_SERVER['PHP_SELF'];
	$cseurl = preg_replace('!'. preg_quote(CSEFILE) .'!', '', $cseurl);

	define('CSEURL', $cseurl);
	unset($cseurl);
}

//
// Date Constants
//
define('DAYS_PER_WEEK', 7);
define('HOURS_PER_WEEK', (DAYS_PER_WEEK*24));
define('MINS_PER_WEEK', (HOURS_PER_WEEK*60));
define('SECS_PER_WEEK', (MINS_PER_WEEK*60));
define('SECS_PER_MIN', 60);
define('SECS_PER_HOUR', (60*SECS_PER_MIN));
define('SECS_PER_DAY', (24*SECS_PER_HOUR));
define('SECS_PER_MONTH', (SECS_PER_DAY*30));
define('SECS_PER_YEAR', (SECS_PER_DAY*365));

// Error reporting level
error_reporting(E_ALL ^ E_NOTICE);

//
// Load core classes and functions
//
require_once CSEPATH .'/cse-functions.php';
unregister_globals();
require_once CSEPATH .'/core/Cinnamon.php';

//
// At this point, we are ready to smell the cinnamon :)
//
Cinnamon::smell();
?>